﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SF.Base.Core;
using Newtonsoft.Json;

namespace SF.Dict.Web {
	public partial class List : BasePage {
		protected void Page_Load(object sender, EventArgs e) {
			if (!Page.IsPostBack) {

				if (Global.DTUser == null) {
					Response.Redirect("/login.aspx?return=List.aspx");
				}

				// 词汇表分类数字ID
				int sid = Request.GetInt("sid", -1);
				string SortId = VocabularyRules.GetStrId(sid);

				

				ucVocSort1.SortId = SortId;

				#region 初始化词汇表列表

				List<VocabularyEntity> vocs = new List<VocabularyEntity>();

				
				if (sid == -1 || string.IsNullOrEmpty(SortId)) {
					vocs = VocabularyRules.GetSystemVocabularys();
				}
				else {
					vocs = VocabularyRules.GetSystemVocabularysByStationId(SortId);
				}
				
				List<VocabularyEntity> Voc_Col1 = new List<VocabularyEntity>();
				List<VocabularyEntity> Voc_Col2 = new List<VocabularyEntity>();
				List<VocabularyEntity> Voc_Col3 = new List<VocabularyEntity>();
				List<VocabularyEntity> Voc_Col4 = new List<VocabularyEntity>();

				int voccount = vocs.Count;

				for (int i = 1; i <= voccount; i++) {
					if (i % 4 == 1) {
						Voc_Col1.Add(vocs[i - 1]);
					}
					if (i % 4 == 2) {
						Voc_Col2.Add(vocs[i - 1]);
					}
					if (i % 4 == 3) {
						Voc_Col3.Add(vocs[i - 1]);
					}
					if (i % 4 == 0) {
						Voc_Col4.Add(vocs[i - 1]);
					}
				}

				rp_voclist_col1.DataSource = Voc_Col1;
				rp_voclist_col1.DataBind();

				rp_voclist_col2.DataSource = Voc_Col2;
				rp_voclist_col2.DataBind();

				rp_voclist_col3.DataSource = Voc_Col3;
				rp_voclist_col3.DataBind();

				rp_voclist_col4.DataSource = Voc_Col4;
				rp_voclist_col4.DataBind();


				#endregion


				#region 获取用户已关注的词汇表

				long[] follows = VocabularyRules.GetUserFollowVocabularyNumIdsByUserId(UserId);
			
				if (!ClientScript.IsClientScriptBlockRegistered("AFollow")) {
					ClientScript.RegisterClientScriptBlock(Page.GetType(), "AFollow", string.Format("var AFollow = {0} ;", JsonConvert.SerializeObject(follows)), true);
				}

				#endregion

			}

		}
	}
}